﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PloobsEngine.SceneControl;

namespace Etapa1.SteeringExperiments
{
    public class Pursuit : Steering
    {

        public Pursuit(IObject target, Deceleration deceleration, float decalerationBeginsAtDistance)
            : base(BehaviorType.seek)
        {
            this.objTarget = target;
            _arrive = new Arrive(objTarget, deceleration, decalerationBeginsAtDistance);
        }

        public Pursuit(IObject target, Deceleration deceleration, float decalerationBeginsAtDistance,float predictionWeight)
            : base(BehaviorType.seek)
        {
            this.objTarget = target;
            _arrive = new Arrive(objTarget, deceleration, decalerationBeginsAtDistance);
            this.predictionWeight = predictionWeight;
        }

        private Arrive _arrive;        
        private IObject objTarget;

        float predictionWeight = 1;

        public float PredictionWeight
        {
            get { return predictionWeight; }
            set { predictionWeight = value; }
        }

        public Deceleration Deceleration
        {
            get { return _arrive.Deceleration; }
            set { _arrive.Deceleration = value; }
        }
        public float DecelerationBeginsAtDistance
        {
            get { return _arrive.DecelerationBeginsAtDistance; }
            set { _arrive.DecelerationBeginsAtDistance= value; }
        }
        
        public IObject ObjTarget
        {
            get { return objTarget; }
            set { objTarget = value;  }
        }

        public override Microsoft.Xna.Framework.Vector3 CalculateSteering(SteeringEntityInfo entity)
        {
            Vector3 ToEvader = objTarget.Position - entity.Obj.Position;

            float LookAheadTime = ToEvader.Length() /
                    (entity.MaxVelocity / 2 + this.objTarget.PhysicObject.Velocity.Length());

            _arrive.Target = this.objTarget.Position + this.objTarget.PhysicObject.Velocity * LookAheadTime * predictionWeight;

            return _arrive.CalculateSteering(entity);
        }
    }
}
